﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SystemManage_GroupEdit : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("100300");
        //btnAdd.Attributes.Add("onclick", "javascript:return confirm('确定删除？');");
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        if (Request.QueryString["ugcode"] != null)
        {
            Label1.Text = "编辑用户组";
            btnAdd.Text = "编辑";
            Model.USERGROUP l = new BLL.USERGROUP().GetModel(Request.QueryString["ugcode"].ToString());
            txtGroupCode.Text = l.UG_CODE;
            txtGroupCode.Enabled = false;
            txtGroupName.Text = l.UG_NAME;
            rbtnTY.SelectedValue = l.UG_STOP.ToString();

            //隐藏密码控件
        }
        else
        {
            
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (txtGroupCode.Text.Trim() == "" || txtGroupName.Text.Trim() == "")
        {
            Share.Alert(this.Page, "请填写完整的信息！"); return;
        }
        Model.USERGROUP l = new Model.USERGROUP();
        l.UG_CODE = txtGroupCode.Text.Trim();
        l.UG_NAME = txtGroupName.Text.Trim();
        l.UG_STOP = Int32.Parse(rbtnTY.SelectedValue);
        if (Request.QueryString["ugcode"] != null)
        {
            if (Check.CheckPermission("100300", "00002"))
            {

                if (new BLL.USERGROUP().Update(l))
                {
                    Share.InsertLog("100300", "00002");
                    Response.Redirect("GroupList.aspx");
                }
                else
                {
                    Share.Alert(this.Page,"操作失败"); return;
                }
            }
            else
            {
                Share.Alert(this.Page,"无权操作"); return;
            }
        }
        else
        {
            if (Check.CheckPermission("100300", "00001"))
            {
                if (new BLL.USERGROUP().Exists(l.UG_CODE))
                {
                    Share.Alert(this.Page, "编号重复"); return;
                }
                else
                {
                    if (new BLL.USERGROUP().Add(l) != null)
                    {
                        Share.InsertLog("100300", "00001");
                        Response.Redirect("GroupList.aspx");
                    }
                    else
                    {
                        Share.Alert(this.Page, "操作失败"); return;
                    }
                }
            }
            else
            {
                Share.Alert(this.Page,"无权操作"); return;
            }
        }
    }

}
